package com.ruoyi.system.mapper.wlwsys;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.common.core.domain.entity.WlwsysProject;
import org.apache.ibatis.annotations.*;

import javax.xml.bind.annotation.XmlSeeAlso;
import java.util.List;

/**
* @author 86187
* @description 针对表【wlwsys_project】的数据库操作Mapper
* @createDate 2023-07-19 17:34:30
* @Entity com.ruoyi.domain.entity.WlwsysProject
*/
@Mapper
public interface WlwsysProjectMapper extends BaseMapper<WlwsysProject> {

    //分页查询，没有时间区间
    @Select("select * from wlwsys_project " +
            "where project_id like concat('%',#{projectId},'%') " +
                "and project_name like concat('%',#{projectName},'%') and user_id like concat('%',#{userId},'%') and is_delete != 1 order by create_time desc")
    @Results(value = {
            @Result(column = "project_id",property = "projectId"),
            @Result(column = "project_name",property = "projectName"),
            @Result(column = "project_introduce",property = "projectIntroduce"),
            @Result(column = "user_id",property = "userId"),
            @Result(column = "create_time",property = "createTime"),
            @Result(column = "update_time",property = "updateTime"),
            @Result(column = "is_delete",property = "isDelete"),
    })
    public List<WlwsysProject> selectProject(@Param("projectId")String projectId,@Param("projectName")String projectName,@Param("userId")String userId);

    //分页查询，有时间区间
    @Select("select * from wlwsys_project " +
            "where project_id like concat('%',#{projectId},'%') " +
            "and project_name like concat('%',#{projectName},'%') and user_id like concat('%',#{userId},'%') " +
            "and #{startTime}<=create_time and #{endTime}>=create_time and is_delete != 1 order by create_time desc")
    @Results(value = {
            @Result(column = "project_id",property = "projectId"),
            @Result(column = "project_name",property = "projectName"),
            @Result(column = "project_introduce",property = "projectIntroduce"),
            @Result(column = "user_id",property = "userId"),
            @Result(column = "create_time",property = "createTime"),
            @Result(column = "update_time",property = "updateTime"),
            @Result(column = "is_delete",property = "isDelete"),
    })
    public List<WlwsysProject> selectProjectHaveTime(@Param("projectId")String projectId,@Param("projectName")String projectName,
                                                     @Param("userId")String userId,@Param("startTime")String startTime,
                                                     @Param("endTime")String endTime);


    //删除数据通过项目ID
    @Results(value = {
            @Result(column = "project_id",property = "projectId"),
            @Result(column = "is_delete",property = "isDelete"),
    })
    @Update("update wlwsys_project set is_delete=true where project_id=#{projectId}")
    public void deleteByProjectId(@Param("projectId") String projectId);

    //更新数据通过项目ID
    @Update("update wlwsys_project set project_name=#{projectName},project_introduce=#{projectIntroduce},update_time=#{updateTime} where project_id=#{projectId}")
    public boolean updateByProjectId(@Param("projectId")String projectId, @Param("projectName")String projectName, @Param("projectIntroduce")String projectIntroduce,
                             @Param("updateTime")String updateTime);

    //新增项目
    @Insert("insert into wlwsys_project values(#{projectId},#{projectName},#{projectIntroduce},#{userId},#{updateTime},#{updateTime},0)")
    public void insertNew(@Param("projectId")String projectId, @Param("projectName")String projectName, @Param("projectIntroduce")String projectIntroduce,
                          @Param("userId")Long userId, @Param("updateTime")String updateTime);

    //查询指定用户下的所有项目名称
    @Select("select project_id from wlwsys_project where user_id=#{userId}")
    @Results(value = {
            @Result(column = "project_id",property = "projectId"),
    })
    public List<String> selectProjectIdByUserIdStrings(Long userId);

    //查询指定用户下的所有项目名称
    @Select("select user_id from wlwsys_project where project_id=#{projectId}")
    @Results(value = {
            @Result(column = "user_id",property = "userId"),
    })
    public Long selectUserIDbyProjectId(String projectId);
}




